﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;

namespace PenguinForce
{
    public class FootstepsController
    {

        public FootstepsController()
        {
            m_footStepList = new List<Footsteps>();
          
        }

        public void Update(GameTime gameTime)
        {
            foreach (Footsteps step in m_footStepList)
            {

                step.Update(gameTime);
            }

            foreach (Footsteps step in new List<Footsteps>(m_footStepList))
            {
                if (step.duration <= 0)
                {
                    m_footStepList.Remove(step);
                }
            }
        }

        public void Draw(GameTime gameTime, SpriteBatch sprite)
        {
       

     
            foreach (Footsteps step in m_footStepList)
              
            {
            
                step.Draw(sprite, m_penguinFeetTexture);
                
            }
        
        }

        public void AddPenguinStep(GameTime gameTime, Vector2 position, Vector2 rotation)
        {
            float elapsedTime = gameTime.ElapsedGameTime.Milliseconds;
            time_elapsed += elapsedTime;

            if (time_elapsed > draw_duration)
            {

                Footsteps newStep = new Footsteps(position, rotation);
                m_footStepList.Add(newStep);
                time_elapsed = 0;
            }

        }

        private float time_elapsed = 0;
        private float draw_duration = 200;
        private List<Footsteps> m_footStepList;
        public Texture2D m_penguinFeetTexture;
    }
}
